/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {boolean}
 */
 var hasPathSum = function(root, targetSum) {
    function digui(root,sum){
        if(!root){
            return false;
        }
        else if(!root.left && !root.right){
            if(sum+root.val==targetSum){
                return true;
            }
            return false;
        }else{
            return digui(root.left,sum+root.val) || digui(root.right,sum+root.val);
            
        }
        
    }
    return digui(root,0);
};